package engine.newUi 
{
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.display.newAttack.AttackLogic;
	import engine.display.newAttack.FightLogic;
	import engine.logic.SceneTransfer;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.tip.TipsMainLogic;
	import engine.ui.AlertUI;
	import engine.ui.UIManage;
	import engine.ui.lite.BaseUI;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	import flash.utils.Timer;
	
	import newx.com.ResManager;
	import newx.com.config.StaticIni;
	import newx.com.control.NxClip;
	import newx.com.control.Scroll.NxScrollPanel;
	import newx.com.control.Scroll.ScrollPolicy;
	import newx.com.control.button.NxButton;
	import newx.com.control.group.NxViewGroup;
	import newx.com.control.text.NxLabel;
	import newx.com.control.window.NxWindowEvent;
	import newx.utils.DateFormatter;
	import newx.utils.FilterUtil;
	
	/**
	 * ...
	 * @author 
	 */
	public class FamilyActiveUI extends BaseUI 
	{
		/**
		 * EXTERMINATE=22 剿匪
		 */		
		private const EXTERMINATE:int=22;
		/**
		 * DINNER 仙宴
		 */		
		private const DINNER:int=20;
		private static var _model			:ModelLocator;
		/***对象自己**/
		private static var _self	:FamilyActiveUI;
		/**所有活动数组*/
		private var allListArr:Array = [];
		/**需要被显示的活动列表***/
		public var showListArr:Array = [];
		public var bg:MovieClip;
		/**服务器数据*/
		private var serviceArr:Array = [];
		private	var	_bindManage			:BindManage;
		
		public  var imgContainer:NxScrollPanel;
		public var lab_info:NxLabel;
		
		/**绑定索引**/
		private var _statusIndex:int = -1;
		
		private var _levelIndex:int = -1;
		/**替身娃娃状态***/
		private var _activityStatusObj:Object = {};
		/**开启关闭状态**/
		private var _activityOpenObj:Object = {};
		/**记录活动数据**/
		private var _activityData:Object = {};
		/**活动列表**/
		private var _activiList:Array = [];
		/**绑定索引**/
		private var _bindIndex:int = -1;
		/**绑定索引**/
		private var _bindvipIndex:int = -1;
		/***当前被点击的ITEM***/
		private var _currClickItem:MovieClip;
		/**boss战设置时间**/
		private var _setTime:String = "";
		/**帮派等级**/
		private var familyLevel:int;
		/**仙宴开启状态**/
		private var _dinnerState:int;
		/**仙宴剩余时间**/
		private var _dinnerLeft:int;
		/**仙宴Timer**/
		private var _dinnerTimer:Timer;
		/**
		 *当前活动状态 
		 */		
		private var _currentActiviesMap:Object={};
		
		private var titleFile:TextField;
		private var currVip:int=0;
		public function FamilyActiveUI(popupUI:Boolean=true) 
		{
			super(popupUI);
		}
		
		public static function getInstance():FamilyActiveUI
		{
			if(_self == null)
			{
				_self	=	new FamilyActiveUI();		
			} 
			return _self
		}
		
		
		override public function Init():void
		{
			_bindManage= BindManage.getInstance();
			_activiList = StaticIni.getIniVar("allFamilyAction","list").split(",");
			lab_info.visible = false;
			//			imgContainer.addView(viewgroup_List);
			imgContainer.horizontalScrollPolicy = ScrollPolicy.OFF;
			imgContainer.verticalScrollPolicy = ScrollPolicy.AUTO;
			imgContainer.vscroll = 0;
			imgContainer.hscroll = 0;
			_model = ModelLocator.getInstance();
			_dinnerTimer = new Timer(1000);
			_dinnerTimer.addEventListener(TimerEvent.TIMER, dinnerTimerHandler);	
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_GUILD_DINNER_NPC_TIPS);
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_GUILD_DINNER), getDinnerTime );
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_GUILD_BANDITI_INFO), getSetTime);
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_ACTIVITY_STATE), onShow);
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_ACTIVITY_SCPEGOST_STATE), onShow);
			//更改帮派BOSS按钮
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_GUILD_BANDITI_STATE), changeBossBtn);
			_bindManage.BindProp(_model.scene.Role,"GuildLevel",this,"GetGuildLevel");
			_bindManage.BindProp(_model.scene.Role,"VIPLevel",this,"GetVIPLevel");
		}

		public function set GetVIPLevel(val:int):void
		{
			currVip=val;
			if(val>=3)
			{
				
				var p:CustomMsgEvent=new CustomMsgEvent(CustomToClientFlag.SERVER_CUSTOMMSG_ACTIVITY_STATE+"",[0,20]);
				onShow(p);
			}
				
		}
		public function set GetGuildLevel(val:int):void
		{
			var exNeedLevel:int =int(StaticIni.getIniVar("action_" + exNeedLevel,"familyLevel"))
			familyLevel=val;
			var p:CustomMsgEvent;
			for  (var i:String in _currentActiviesMap) 
			{
				refreshIDState(int(i),_currentActiviesMap[i]);
			}
		}
		/**
		 * 更改BOSS按钮状态
		 */
		private function changeBossBtn(e:CustomMsgEvent):void
		{
			var serverArr:Array = e.pList;
			changeBossState(serverArr[0])
		}
		//-----------------侦听帮派仙宴
		//GuildDinnerSTC_Visiable = 1,		// 帮派宴会是否可见
		//GuildDinnerSTC_OnLoad	= 2,		// 玩家登录,帮派宴会通知
		//GuildDinnerSTC_OpenUI	= 3,		// 玩家打开帮派活动界面,帮派宴会提示
		//GuildDinnerSTC_Begin	= 4,		// 帮派宴会开始
		//GuildDinnerSTC_Tips	= 5,		// 帮派宴会TIPS
		private function getDinnerTime(e:CustomMsgEvent):void
		{
			var serverArr:Array = e.pList;
			var index:int=serverArr[0];
			if(index == 5)
			{
				_dinnerLeft = serverArr[2];
		
			}
			else if(index ==6)
			{
				_dinnerLeft=serverArr[1];
				var p:CustomMsgEvent	= 	new CustomMsgEvent(CustomToClientFlag.SERVER_CUSTOMMSG_ACTIVITY_STATE+"",[_currentActiviesMap[20],20]);
				onShow(p);
			}
			else if(index == 2 || index == 4)
			{
				var name:String = serverArr[1];
				if(AttackLogic.getInstance().fighting) return;
				AlertUI.showAlert(StaticIni.getSwfLangStr("UIString_1000662"),StaticIni.getSwfLangStrVar("CocktailStr_8",[name]),AlertUI.OK | AlertUI.CANCEL,
					function(type:int, str:String, clickData:*):void{
						if(type == AlertUI.OK){
							//进入帮派总坛
							SystemSender.getInstance().CustomMsg(
								CustomToServerFlag.CLIENT_CUSTOMMSG_PLAYER_GUILD_SCENE);
						}
					},null,false,300,150,"",null,StaticIni.getSwfLangStr("CocktailStr_9"), 	StaticIni.getSwfLangStr("CocktailStr_10"));
			}
		}
		
		
		private function checkItem(id:String):MovieClip
		{
			for(var i:int = 0;i<showListArr.length;i++)
			{
				if(showListArr[i]["Data"]["id"] == id)
				{
					return showListArr[i];
				}
			}
			return null;
		}
		
		private function checkAfk(id:int):int
		{
			var arr:Array = _model.scene.GetRecordEx("Scapegoat").recArr;
			for(var i:int = 0;i < arr.length;i++)
			{
				if(arr[i][0] == id)
					return arr[i][2];
			}
			return 0;
		}
		
		private function onShow(e:CustomMsgEvent):void
		{
			serviceArr 					     = e.pList;
			
			var state					:int = serviceArr[0]; //是否创建新的活动0.关闭，1开启。2.结束
			var id						:int = serviceArr[1]; //活动ID
			var style					:int = serviceArr[2];//活动类型2：全天3：定时
			
			if(id==EXTERMINATE)
			{
				state=_currentActiviesMap[EXTERMINATE];
			}
			_currentActiviesMap[id]=state;
			//			var isOver					:int = serviceArr[3];//活动是否结束  0没结束。1结束
			//	var isContain				:int= sendIdArr.indexOf(id);//过滤服务器重复发送同一消息
			var status					:int = checkAfk(id);//serviceArr[3];//是否在替身娃娃中 0.不在。1在
			var isVip					:int = _model.scene.Role.GetProperties("VIPLevel")//(new RoleVo()).getPlayerLevel();
//			familyLevel				         = _model.scene.Role.GetProperties("GuildLevel");//帮派等级
			var familyPostion			:int = _model.scene.Role.GetProperties("GuildPosition");//帮派职务
				
			var obj:Object = {};
			obj.id = id;
			obj.state = state;
			obj.style = style;
			obj.status = status;
			obj.isVip = isVip;
			obj.familyPostion = familyPostion;
			_activityOpenObj[id] = state;
			_activityData [id] = obj;
			var mc:MovieClip = checkItem(String(id)) as MovieClip;
			//			if(id == 1)return;
			if(_activiList.indexOf("action_"+id) == -1)return;
			var itemObj:Object		= StaticIni.getIniObj("action_"+id) ;
			var level:int = _model.scene.Role.getPlayerLevel();
			if(level < int(itemObj.Level))return;
			if(id == DINNER){
				_dinnerState = state;
			}
			if(mc && id == EXTERMINATE){
				if(_setTime ==""||state==2)
				{
					mc.titleTxt.htmlText=StaticIni.getSwfLangStrVar("ActivityTipsStr_22",[""]);
				}
				else
				{
					mc.titleTxt.htmlText = StaticIni.getSwfLangStrVar("ActivityTipsStr_22",[_setTime]);
				}
			}
			if(mc == null)
			{
				mc = ResManager.newResClass("Castle_Item_22") as MovieClip;
				
				//				mc = viewgroup_List.getChildAt(viewgroup_List.row-1) as MovieClip;
				
				addLevBtn(mc);
				showListArr.push(mc);
				displayActivityList(id.toString(),mc);
			}
			var o:Object = mc["Data"];
			//
			mc["Data"]["id"] = id;
			mc["Data"]["state"] = state;
			mc["Data"]["style"] = style;
			var count:int = mc.numChildren;
			var statuLab:NxLabel = mc.getChildAt(count - 4) as NxLabel;
			var btn:NxButton = mc.getChildAt(count - 3) as NxButton;
			var lab:NxLabel  = mc.getChildAt(count - 2) as NxLabel;
			var checkBox:MovieClip = mc.getChildAt(count - 1) as MovieClip;
			
			var isOpen:int = int(StaticIni.getIniVar("action_" + id,"isOpen"));
			var needLevel:int = int(StaticIni.getIniVar("action_" + id,"familyLevel"));
			
			if (state == 1 )
			{//开启
				btn.visible = true;
				checkBox.visible = true;
				statuLab.visible = false;
				checkBox.enabled = checkBox.mouseChildren = checkBox.mouseEnabled =  false;
				lab.visible = true;
				if(status == 1)
				{//替身娃娃中
					btn.enabled = false;
					checkBox.gotoAndStop(2);
					lab.htmlStr = StaticIni.getSwfLangStr("UIString_1000130");
				}else
				{
					btn.enabled = true;
					checkBox.gotoAndStop(1);
					lab.htmlStr = StaticIni.getSwfLangStr("UIString_1000129");
					btn.label = StaticIni.getSwfLangStr("UIStr_1001750") ;
				}
				if(id == DINNER){
					btn.filters=null;
					btn.enabled = true;
					checkBox.gotoAndStop(1);
					lab.htmlStr = StaticIni.getSwfLangStr("UIString_1000129");
					btn.label = StaticIni.getSwfLangStr("UIString_1000126") ;
					updateInfo(String(id),mc);
				}
				if(id == EXTERMINATE){
					if(familyLevel >= needLevel){
						btn.enabled = true;
						checkBox.gotoAndStop(1);
						lab.htmlStr = StaticIni.getSwfLangStr("UIString_1000129");
						btn.label = StaticIni.getSwfLangStr("UIStr_1001750") ;
					} else {
						btn.visible = false;
						checkBox.visible = true;
						checkBox.enabled = checkBox.mouseChildren = checkBox.mouseEnabled = true;
						lab.htmlStr = StaticIni.getSwfLangStr("UIString_1000129");
						lab.visible = true;
						statuLab.visible = true;
						statuLab.htmlStr = StaticIni.getSwfLangStrVar("UIString_1000373", [needLevel]);
					}
				}
				if(mc["Data"]["itemPic"]["effect1"] != null){
					mc["Data"]["itemPic"]["effect1"].visible = true;
					mc["Data"]["itemPic"]["effect1"].play();
//					mc["Data"]["itemPic"]["effect1"].visible = false;
//					mc["Data"]["itemPic"]["effect1"].stop();
				}
				
			}
			else if(state == 0)
			{//关闭
				
				//活动关闭，帮派等级不够
				if(familyLevel >= needLevel)
				{
					//活动关闭，帮主可开启
					if(isOpen == 1)
					{
						if(familyPostion == 1 || familyPostion == 2||id==EXTERMINATE){
							btn.visible = true;
							checkBox.visible = false;
							lab.visible = false;
							statuLab.visible = false;
							btn.label = StaticIni.getSwfLangStr("UIString_1000368") ;
						} else 
						{
							btn.visible = false;
							checkBox.visible = true;
							checkBox.enabled = checkBox.mouseChildren = checkBox.mouseEnabled = true;
							lab.htmlStr = StaticIni.getSwfLangStr("UIString_1000129");
							lab.visible = true;
							statuLab.visible = true;
							statuLab.htmlStr = StaticIni.getSwfLangStr("UIString_1000127");
						}
					} 
					else 
					{
						btn.visible = false;
						checkBox.visible = true;
						checkBox.enabled = checkBox.mouseChildren = checkBox.mouseEnabled = true;
						lab.htmlStr = StaticIni.getSwfLangStr("UIString_1000129");
						lab.visible = true;
						statuLab.visible = true;
						statuLab.htmlStr = StaticIni.getSwfLangStr("UIString_1000127");
						if(id == 13)
						{
							btn.visible = true;
							checkBox.visible = false;
							lab.visible = false;
							statuLab.visible = false;
							btn.label = StaticIni.getSwfLangStr("UIString_1000266") ;
						} else if(id == DINNER)
						{
							btn.visible = true;
							checkBox.visible = false;
							lab.visible = false;
							statuLab.visible = false;
							btn.label = StaticIni.getSwfLangStr("UIString_1000252") ;
							var currVipLv:int=_model.scene.Role.getVipLevel();
							if(currVipLv>=3)
							{
								btn.filters=null;
								btn.mouseChildren=true;
								btn.mouseEnabled=true;
							}
							else
							{
								btn.filters=[FilterUtil.GrayColorFilter];
		
							}
							if(checkItem(String(DINNER)))
							{
								updateInfo(String(DINNER),checkItem(String(DINNER)));
							}
						}
					}
					
				}
				else
				{
					
					btn.visible = false;
					checkBox.visible = true;
					checkBox.enabled = checkBox.mouseChildren = checkBox.mouseEnabled = true;
					lab.htmlStr = StaticIni.getSwfLangStr("UIString_1000129");
					lab.visible = true;
					statuLab.visible = true;
					statuLab.htmlStr = StaticIni.getSwfLangStrVar("UIString_1000373", [needLevel]);
					if(checkItem(String(DINNER)))
					{
						updateInfo(String(DINNER),checkItem(String(DINNER)));
					}
				}
				if(status == 1)
				{//替身娃娃中
					checkBox.gotoAndStop(2);
				}else
				{
					checkBox.gotoAndStop(1);
				}
//				updateInfo(String(id),mc);
				if(mc["Data"]["itemPic"]["effect1"] != null){
					mc["Data"]["itemPic"]["effect1"].visible = false;
					mc["Data"]["itemPic"]["effect1"].stop();
				}
			}
			else if(state==5) //开启后加入的不能参与
			{
				if(id ==DINNER)
				{
					updateInfo(String(id),mc);
					statuLab.visible = false;
					btn.label = StaticIni.getSwfLangStr("CocktailStr_12") ;
					btn.filters=[FilterUtil.GrayColorFilter];
					btn.visible=true;
			
					
				}
				if(mc["Data"]["itemPic"]["effect1"] != null){
					mc["Data"]["itemPic"]["effect1"].visible = false;
					mc["Data"]["itemPic"]["effect1"].stop();
				}
			}
			else if(state==6) //已参与
			{
				if(id == DINNER)
				{
					updateInfo(String(id),mc);
					statuLab.visible = true;
					statuLab.htmlStr = StaticIni.getSwfLangStr("CocktailStr_16");
					btn.filters=null;
					btn.visible = false;
				}
				if(mc["Data"]["itemPic"]["effect1"] != null){
					mc["Data"]["itemPic"]["effect1"].visible = false;
					mc["Data"]["itemPic"]["effect1"].stop();
				}
			}
			else
			{//结束
				_dinnerTimer.stop();
				btn.filters=null;
				btn.visible = false;
				checkBox.visible = true;
				checkBox.enabled = checkBox.mouseChildren = checkBox.mouseEnabled = true;
				lab.htmlStr = StaticIni.getSwfLangStr("UIString_1000129");
				lab.visible = true;
				statuLab.visible = true;
				statuLab.htmlStr = StaticIni.getSwfLangStr("UIString_1000128");
				if(status == 1)
				{//替身娃娃中
					checkBox.gotoAndStop(2);
				}else
				{
					checkBox.gotoAndStop(1);
				}
				
				if(id == 13)
				{
					btn.visible = true;
					checkBox.visible = false;
					lab.visible = false;
					statuLab.visible = false;
					btn.label = StaticIni.getSwfLangStr("UIString_1000368")//查看;
				}
				if(id ==DINNER)
				{
					lab.visible = false;
					checkBox.visible = false;
					_dinnerTimer.stop();
					updateInfo(String(id),mc);
					
				}
//				if(id==EXTERMINATE)
//				{
//					if(familyPostion == 1 || familyPostion == 2){
//						btn.visible = true;
//						checkBox.visible = false;
//						lab.visible = false;
//						statuLab.visible = false;
//						btn.label = StaticIni.getSwfLangStr("UIString_1000368") ;
//						mc.titleTxt.htmlText=StaticIni.getSwfLangStrVar("ActivityTipsStr_22",[""]);
//					}
//				}
				if(mc["Data"]["itemPic"]["effect1"] != null){
					mc["Data"]["itemPic"]["effect1"].visible = false;
					mc["Data"]["itemPic"]["effect1"].stop();
				}
			}
			//活动本身能不能使用替身娃娃功能
			var isShowAfk:int = int( StaticIni.getIniVar("action_"+id,"isShowAFK"));
			if(currVip < 5 || isShowAfk == 0)
			{//是不是VIP
				checkBox.visible = false;
				lab.visible = false;
			}else
			{
				checkBox.visible = true;
				lab.visible = true
			}
			setEffect();
		} 
		
		/**
		 *显示或者移除特效 
		 * 
		 */
		public function setEffect():void
		{
			for(var i:int = 0;i<showListArr.length;i++)
			{
				if(showListArr[i]["Data"]["state"] == "1")
				{
					ActivitesGroupLogic.getInstance().addEffect(19);
					return ;
				}
				ActivitesGroupLogic.getInstance().removeEffect(19);
			}
		}
		
		
		/***获取所有活动列表**/
		public  function getActiviList():void
		{
			var listStr:String = StaticIni.getIniObj("allFamilyAction")["list"];
			allListArr = listStr.split(",");
		}
		
		
		/**
		 *给NxviewGroup添加参加按纽 
		 * @param viewItem
		 * 
		 */
		private function addLevBtn(viewItem:MovieClip):void
		{
			var statusLab:NxLabel = new NxLabel();
			statusLab.text = StaticIni.getSwfLangStr("UIString_1000127");
			statusLab.x = 300;
			statusLab.y = 35;
			
			var leve:NxButton = new  NxButton();
			leve.label = StaticIni.getSwfLangStr("UIString_1000126");
			leve.width = 50;
			leve.height = 26;
			leve.x = 300;
			leve.y = 30;
			leve.skin = "Button_20";
			leve.	addEventListener(MouseEvent.CLICK,viewGroupout);
			leve.	addEventListener(MouseEvent.MOUSE_OVER,onOver);
			leve.	addEventListener(MouseEvent.MOUSE_OUT,onOut);
			
			var lab:NxLabel = new NxLabel();
			lab.text = StaticIni.getSwfLangStr("UIString_1000129");
			lab.x = 285;
			lab.y = 55;
			lab.	addEventListener(MouseEvent.MOUSE_OVER,babyOverHandle);
			lab.	addEventListener(MouseEvent.MOUSE_OUT,babyOutHandle);
			
			
			var checkBox:MovieClip = new MovieClip(); 
			checkBox = ResManager.newResClass("custSkin_13") as MovieClip;
			checkBox.x = 350;
			checkBox.y = 55;
			checkBox.buttonMode = true;
			checkBox.gotoAndStop(1);
			checkBox.	addEventListener(MouseEvent.CLICK,checkBoxClickHandle);
			checkBox.	addEventListener(MouseEvent.MOUSE_OVER,babyOverHandle);
			checkBox.	addEventListener(MouseEvent.MOUSE_OUT,babyOutHandle);
			
			viewItem.addChild(statusLab);
			viewItem.addChild(leve);
			viewItem.addChild(lab);
			viewItem.addChild(checkBox);
			viewItem["checkBox"] = checkBox;
			
		}
		private function onOver(e:MouseEvent):void
		{
			var sceneID:String 					= e.currentTarget.parent.Data["transition"];
			var id:String = e.currentTarget.parent.Data["id"];
			var state:int = int(e.currentTarget.parent.Data["state"]);
			if(int(id)==20)
			{
				var strID:String="";
				switch(state)
				{
					case 0:
						strID="CocktailStr_5";
						break;
					case 1:
						strID="CocktailStr_12";
						break;
					case 2:
						strID="CocktailStr_17";
						break;
					case 5:
						strID="CocktailStr_13";
						break;
				}
				TipsMainLogic.instance.showString(StaticIni.getSwfLangStr(strID));
			}
		}
		private function onOut(e:MouseEvent):void
		{
			TipsMainLogic.instance.hide();
		}
		private function babyOverHandle(e:MouseEvent):void
		{
			var dataArr:Array = _model.scene.GetRecordEx("ScapegoatComsumeNotes").recArr;
			var item:MovieClip = e.currentTarget.parent as MovieClip;
			var id:int = item["Data"]["id"];
			for(var i:int = 0;i<dataArr.length;i++)
			{
				if(dataArr[i][0] == id)
				{
					if(dataArr[i][1]== 0 && dataArr[i][2] == 0)
					{
						TipsMainLogic.instance.showMain(StaticIni.getSwfLangStrVar("BaiShiTipsStr_15",[StaticIni.getSwfLangStr("ActivityStr_"+id)]));
					}else
					{
						TipsMainLogic.instance.showMain(StaticIni.getSwfLangStrVar("BaiShiTipsStr_16",[StaticIni.getSwfLangStr("ActivityStr_"+id),dataArr[i][1],dataArr[i][2]]));
					}
					return;
				}
			}
		}
		
		private function babyOutHandle(e:MouseEvent):void
		{
			TipsMainLogic.instance.hide();
		}
		
		
		private function checkBoxClickHandle(e:MouseEvent):void
		{
			var sceneID:String 					= e.currentTarget.parent.Data["transition"];
			var id:String = e.currentTarget.parent.Data["id"];
			var style:String  =  e.currentTarget.parent.Data["style"]; 
			var mc:MovieClip = e.currentTarget as MovieClip;
			if(mc.currentFrame == 1)
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_CHANGE_SCAPEGOAT_STATE,int(id),1);//开启替身娃娃
				
			}else
			{
				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_CHANGE_SCAPEGOAT_STATE,int(id),0);//关闭替身娃娃
				
			}
		}
		
		private function showAlter():void
		{
			AlertUI.showAlert(StaticIni.getSwfLangStr("UIString_1000084"),StaticIni.getSwfLangStr("CocktailStr_6"),AlertUI.YES|AlertUI.NO,backFunc);
		}
		private function backFunc(type:int,str:String,clickData:*):void
		{
			if(AlertUI.YES == type)
			{
				//请求开启帮派仙宴 
				SystemSender.getInstance().CustomMsg( CustomToServerFlag. CLIENT_CUSTOMMSG_AFFIRM_CHARGE, 19 );
			}
		}
		/**
		 *参加按纽事件 a
		 * @param e
		 * 
		 */
		private function viewGroupout(e:MouseEvent):void
		{
//			var sceneID:String 					= e.currentTarget.parent.Data["transition"];
			var sceneID:String 					= e.currentTarget.parent.Data["transition1"];
			var id:String = e.currentTarget.parent.Data["id"];
			var state:int = int(e.currentTarget.parent.Data["state"]);
			//仙宴
			if(id == "20"){
				if(state == 1){
					//进入帮派总坛
//					SystemSender.getInstance().CustomMsg(
//						CustomToServerFlag.CLIENT_CUSTOMMSG_PLAYER_GUILD_SCENE);
					SceneTransfer.getInstance().tranferTo(sceneID);
				} else if( state == 0)
				{
					var currVip:int=_model.scene.Role.getVipLevel();
					if(currVip>=3)
					{
						//请求开启帮派仙宴 
						showAlter();
					}
					
				}
			//答题
			} else if(id == "21"){
				UIManage.getInstance().requestOpenUI(QuestionUI.getInstance());
			}else if(id	==	EXTERMINATE+"")
			{
				//查看
				if(e.currentTarget["label"]==StaticIni.getSwfLangStr("UIString_1000368"))
				{
					BossTimeSetUI.getInstance().showOrHide();
				}
				else
				{
					//参加剿匪 发固定连接号~~~~~~~~~~~~~~~~~~~~~
//					trace("FamilyActiveUI.viewGroupout(e)参加剿匪");
					SceneTransfer.getInstance().tranferTo("75011017");
//					SceneTransfer.getInstance().tranferTo(sceneID);
				}
			}
			else {
				SceneTransfer.getInstance().tranferTo(sceneID);
//				SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_SCENE_TRANSFER_REQUEST,sceneID);//服务器发送场景ID
			}
//			_currClickItem = e.currentTarget.parent as MovieClip;
		}
		/**
		 *状态改变更新显示信息 
		 * @param id
		 * @param mc
		 * 
		 */		
		private function updateInfo(id:String,mc:MovieClip):void
		{
			var itemObj:Object		= StaticIni.getIniObj("action_"+id) ;
			
			var iconPath		:String			=	itemObj["picName"];//图片地址
			var txtContent		:String			=	itemObj["description"];	//显示文本
			var transition		:String			=	itemObj["transition"];	//操作指令
			var enterLv			:int			=	int(itemObj["enterLv"]);//进入等级
			var needlevel		:int			=	int(itemObj["familyLevel"]);//所需等级
			var viewItem:MovieClip	=	mc;//viewgroup_List.getItemByIndex(index) as MovieClip;
			 titleFile  = viewItem.titleTxt as TextField;
			if(int(id) == DINNER && _dinnerState == 0)
			{
				titleFile.htmlText = StaticIni.getSwfLangStrVar("ActivityTipsStr_20",
					[StaticIni.getSwfLangStrVar("CocktailStr_2",[1])]);
			} 
			else if(int(id) == DINNER && _dinnerState == 1)
			{
				if(_dinnerLeft != 0)
				{
					var time:String = DateFormatter.SecondFormart(_dinnerLeft);
					titleFile.htmlText = StaticIni.getSwfLangStrVar("ActivityTipsStr_20",
						[StaticIni.getSwfLangStrVar("CocktailStr_11",[time])]);

					_dinnerTimer.stop();
					_dinnerTimer.start();
				
				}
			}
			else if(int(id) == DINNER && _dinnerState == 5)  //开启后加入的不能参与
			{
				updateState();
			}
			else if(int(id) == DINNER && _dinnerState == 6) //已参与
			{
				updateState();
			}
			else if(int(id) == DINNER && _dinnerState == 2) //活动结束
			{
				titleFile.htmlText = StaticIni.getSwfLangStrVar("ActivityTipsStr_20",
					[StaticIni.getSwfLangStrVar("CocktailStr_2",[0])]);
			}
		}
		private function updateState():void
		{
			if(_dinnerLeft != 0)
			{
				var time2:String = DateFormatter.SecondFormart(_dinnerLeft);
				titleFile.htmlText = StaticIni.getSwfLangStrVar("ActivityTipsStr_20",
					[StaticIni.getSwfLangStrVar("CocktailStr_11",[time2])]);
				
				_dinnerTimer.stop();
				_dinnerTimer.start();
				
			}
			else
			{
				_dinnerTimer.stop();
				titleFile.htmlText = StaticIni.getSwfLangStrVar("ActivityTipsStr_20",
					[StaticIni.getSwfLangStrVar("CocktailStr_2",[0])]);
			}
		}
		private function dinnerTimerHandler(e:TimerEvent):void
		{
			_dinnerLeft --;
			var time:String = DateFormatter.SecondFormart(_dinnerLeft);
			titleFile.htmlText = StaticIni.getSwfLangStrVar("ActivityTipsStr_20",
				[StaticIni.getSwfLangStrVar("CocktailStr_11",[time])]);
			if(_model.scene.Role.GetProperties("GuildName")=="")
			{
				_dinnerTimer.stop();
			}
			if(_dinnerLeft==0)
			{
				_dinnerTimer.reset();
				titleFile.htmlText = StaticIni.getSwfLangStrVar("ActivityTipsStr_20",
					[StaticIni.getSwfLangStrVar("CocktailStr_2",[0])]);
			}
		}
		
		private function sortList():void
		{
			mcList.sortOn("id",Array.NUMERIC);
//				function (left:int,right:int):int
//			{
//				if(left>right)
//				{
//					return 1;
//				}
//				return -1; 
//			});
			var maxViewNum:int	=	showListArr.length;
			for(var i:int = 0;i<mcList.length;i++)
			{
				var mc:MovieClip = mcList[i]["mc"] as MovieClip;
				
				mc.y = 80 *i;
			}
		}
		
		private var mcList:Array = [];
		
		/***显示活动**/
		private function displayActivityList(id:String,mc:MovieClip):void
		{
			//所要设定图片组的最大显示数
			var maxViewNum:int	=	showListArr.length;
			
			mc.y = mc.height *( maxViewNum-1);
			imgContainer.addView(mc);
			if (maxViewNum >= 4)
			{
				this.windowBG.height = 57+mc.height*4;
				imgContainer.viewHeight = 20 + mc.height*4;
				
				lab_info.visible = false ;
			}else if (maxViewNum <= 0)
			{
				lab_info.visible = true;
				this.windowBG.height = 50 + mc.height * 1;
				imgContainer.viewHeight =  20 + mc.height * 1;
			}else
			{
				lab_info.visible = false;
				this.windowBG.height = 50 + mc.height * maxViewNum;
				imgContainer.viewHeight =  20 + mc.height * maxViewNum;
			}
			bg.height		=	this.windowBG.height	-	45;
			var itemObj:Object		= StaticIni.getIniObj("action_"+id) ;
			
			var iconPath		:String			=	itemObj["picName"];//图片地址
			var txtContent		:String			=	itemObj["description"];	//显示文本
			var transition		:String			=	itemObj["transition"];	//操作指令
			var enterLv			:int			=	int(itemObj["enterLv"]);//进入等级
			var needlevel		:int			=	int(itemObj["familyLevel"]);//所需等级
			var viewItem:MovieClip	=	mc;//viewgroup_List.getItemByIndex(index) as MovieClip;
			
			var viewPic :NxClip		=	new NxClip();
			viewPic.x = 0;
			viewPic.y = 0;
			viewItem["Data"]					=	itemObj;
			viewItem["Data"]["id"] = id;
			
			var str:String = StaticIni.getSwfLangStr(txtContent);
			var titleFile:TextField  = viewItem.titleTxt as TextField;
			titleFile.width  = 300;
			titleFile.height = 100;
			titleFile.mouseEnabled =  false;
			
			if( null != str )
			{
				if(int(id) == DINNER && _dinnerState == 0){
					titleFile.htmlText = StaticIni.getSwfLangStrVar("ActivityTipsStr_20",
												[StaticIni.getSwfLangStrVar("CocktailStr_2",[1])]);
				}
				else if(int(id) == DINNER && _dinnerState == 1)
				{
					if(_dinnerLeft != 0){
						var time:String = DateFormatter.SecondFormart(_dinnerLeft);
						titleFile.htmlText = StaticIni.getSwfLangStrVar("ActivityTipsStr_20",
													[StaticIni.getSwfLangStrVar("CocktailStr_11",[time])]);

						_dinnerTimer.stop();
						_dinnerTimer.start();
				
					}
				}
				else if(int(id) == DINNER && _dinnerState == 2){
					if(_dinnerLeft==0)
					{
						_dinnerTimer.stop();
						titleFile.htmlText = StaticIni.getSwfLangStrVar("ActivityTipsStr_20",
							[StaticIni.getSwfLangStrVar("CocktailStr_2",[0])]);
					}
					else
					{
						var time2:String = DateFormatter.SecondFormart(_dinnerLeft);
						titleFile.htmlText = StaticIni.getSwfLangStrVar("ActivityTipsStr_20",
							[StaticIni.getSwfLangStrVar("CocktailStr_11",[time2])]);
						
						_dinnerTimer.stop();
						_dinnerTimer.start();
					}
				
				}
				
				else if(int(id) == EXTERMINATE){
					if(_setTime =="" || familyLevel < needlevel)
					{
						titleFile.htmlText=StaticIni.getSwfLangStrVar("ActivityTipsStr_21",[""]);
					}
					else
					{
						titleFile.htmlText = StaticIni.getSwfLangStrVar("ActivityTipsStr_21",[_setTime]);
					}
					
				} else {
					titleFile.htmlText = str;
				}
			}
			
			var mcpic:MovieClip = ResManager.newResClass(iconPath) as MovieClip;
//			if(familyLevel >= needlevel){
				mcpic.gotoAndStop(1);
//			} else {
//				mcpic.gotoAndStop(2);
//			}
			viewPic.source = mcpic;
			viewItem.img2.addChild(viewPic);
			viewItem["Data"]["itemPic"] = mcpic;
			var eff:MovieClip =  ResManager.newResClass("custSkin_200") as MovieClip;
//			viewItem.img2.addChild(eff);
//			viewItem["eff"] = eff;
			//			imgContainer.viewHeight = viewgroup_List.height;
			//			imgContainer.viewHeight = mc.y+mc.height;
			mcList.push({id:id,mc:viewItem});
		}
		
		
		/**
		 *  清空指定图片组
		 * @param viewGroupType 所要清空的图片组
		 * 
		 */		
		private function clearViewGroup(viewGroupType:NxViewGroup):void
		{
			//当前图片组最大显示数
			var maxNmu:int	=	viewGroupType.row * viewGroupType.col;
			for(var i:int = 0; i < maxNmu; i++)
			{
				var viewItem:MovieClip			=	viewGroupType.getItemByIndex(i) as MovieClip;
				viewItem. data					=	null;
				viewItem. titleTxt. htmlText	=	"";
				if(viewItem.numChildren>1)
				{
					viewItem.removeChildAt(viewItem.numChildren-1);
					viewItem.removeChildAt(viewItem.numChildren-1);
					viewItem.removeChildAt(viewItem.numChildren-1);
				}
				
				while(viewItem.img2.numChildren>0)
				{
					viewItem.img2.removeChildAt(0);
					viewItem["Data"]	=	null;
				}
			}
		}
		/**
		 *关闭界面 
		 * @param e
		 * 
		 */
		private function onClickClose(e:NxWindowEvent):void
		{
			removeListenter();
			this.showOrHide();			
		}
		
		/**
		 * 替身娃娃表变化
		 */	
		public function onaddPerHandle(PropertiesName:String,PropertiesValue:Array,data:*):void
		{
			
			var mc:MovieClip = checkItem(String(PropertiesValue[0])) as MovieClip;
			if(mc != null)
			{
				var count:int = mc.numChildren;
				var checkBox:MovieClip = mc["checkBox"] as MovieClip;
				
				checkBox.gotoAndStop(PropertiesValue[2]+1);
			}
		}
		
		/**
		 *在这里用不到 
		 */		
		public function onremovePerHandle(PropertiesName:String,PropertiesValue:Array,data:*):void
		{		
			//			BindManage.getInstance().UnbindRecord("Scapegoat",_bindIndex);
		}
		
		/**
		 *添加监听 
		 * 
		 */
		private function addListenter():void
		{
			windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,onClickClose);
		}
		
		
		/**
		 *移除监听 
		 * 
		 */
		private function removeListenter():void
		{
			windowBG.removeEventListener(NxWindowEvent.WINDOW_CLOSE,onClickClose);
			BindManage.getInstance().UnbindRecord("Scapegoat",_bindIndex);
			BindManage.getInstance().UnbindProp(_model.scene.Role,"VIPLevel",_bindvipIndex);
		}
		
		private function updataStatus():void
		{
			
		}
		
		public function set onVipLevelChenge(value:int):void 
		{
			BindManage.getInstance().UnbindRecord("Scapegoat",_bindIndex);
			_bindIndex = 	BindManage.getInstance().BindRecord(_model.scene,"Scapegoat",onaddPerHandle,onremovePerHandle);
		}
		
		override protected function BeforeShow():void
		{
			_bindIndex = 	BindManage.getInstance().BindRecord(_model.scene,"Scapegoat",onaddPerHandle,onremovePerHandle);
			_bindvipIndex = BindManage.getInstance().BindProp(_model.scene.Role,"VIPLevel",this,"onVipLevelChenge");
			if(showListArr.length < 1)
			{
				lab_info.visible = true;
				this.windowBG.height = 50 + 75 * 1;
				bg.height		=	this.windowBG.height	-	45;
			}
			imgContainer.viewHeight = 75 *( showListArr.length)+25;
			imgContainer.height = 320;
			imgContainer.viewWidth = 380;
			imgContainer.width = 380;
			imgContainer.vscroll = 0;
			addListenter();
			sortList();
			
		}
		
		override protected function AfterHide():void
		{
			removeListenter();
		}
		private function refreshIDState(id:int,state:int):void
		{
			onShow(new CustomMsgEvent(CustomToClientFlag.SERVER_CUSTOMMSG_ACTIVITY_STATE+"",[state,id]));
 		}
		/**
		 *改变状态 
		 * @param state
		 * 
		 */		
		private function changeBossState(state:int):void
		{
			_currentActiviesMap[EXTERMINATE]=state;
//			var position:int=_model.scene.Role.GetProperties("GuildPosition");
//			if(_currentActiviesMap[EXTERMINATE]==2&&(position==1||position==2))
//			{
//				_currentActiviesMap[EXTERMINATE]	=	3;
//			}
			refreshIDState(EXTERMINATE,_currentActiviesMap[EXTERMINATE])
		}
		//获取帮派剿匪信息
		//时间索引1 0未选择 1-7时间
		//状态1  0完成结束 1等待开启
		//时间索引2 
		//状态2
		//获得状态
		private function getSetTime(e:CustomMsgEvent):void
		{
			var serverArr:Array = e.pList;
			_setTime="";
			var _day:String;
			if(serverArr[0]<serverArr[2])
			{
				if(serverArr[1] == 0)
				{
					_day = "day" + serverArr[0];
				} 
				else
				{
					_day = "day" + serverArr[2];
				}
			}
			else
			{
				if(serverArr[3] == 0)
				{
					_day = "day" + serverArr[2];
				} 
				else
				{
					_day = "day" + serverArr[0];
				}
			}
			switch(_day){
				case "day1":
					_setTime = StaticIni.getSwfLangStr("UIString_1000360");
					break;
				case "day2":
					_setTime = StaticIni.getSwfLangStr("UIString_1000361");
					break;
				case "day3":
					_setTime = StaticIni.getSwfLangStr("UIString_1000362");
					break;
				case "day4":
					_setTime = StaticIni.getSwfLangStr("UIString_1000363");
					break;
				case "day5":
					_setTime = StaticIni.getSwfLangStr("UIString_1000364");
					break;
				case "day6":
					_setTime = StaticIni.getSwfLangStr("UIString_1000365");
					break;
				case "day7":
					_setTime = StaticIni.getSwfLangStr("UIString_1000366");
					break;
			}
//			if(serverArr[4]!=_currentActiviesMap[EXTERMINATE])
//			{
				changeBossState(serverArr[4])
//			}
//			_currClickItem.Data["description"] += _setTime;
		}
	}
	
}